local wdtx__axeSkill = fk.CreateSkill {
  name = "#wdtx__axe_skill",
  attached_equip = "wdtx__axe",
}

wdtx__axeSkill:addEffect(fk.CardEffectCancelledOut, {
  name = "#wdtx__axe_skill",
  priority = 11,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(wdtx__axeSkill.name) then return end
    return data.from == player and data.card.trueName == "slash" and not data.to.dead
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardEffectCancelledOut then
      local pattern
      if player:getEquipment(Card.SubtypeWeapon) then
        pattern = ".|.|.|.|.|.|^" .. tostring(player:getEquipment(Card.SubtypeWeapon))
      else
        pattern = "."
      end
      local cards = room:askToDiscard(player, {
        min_num = 2,
        max_num = 2,
        prompt = "#axe-invoke::" .. data.to.id,
        skill_name = wdtx__axeSkill.name,
        cancelable = true,
        include_equip = true,
      })
      if #cards > 0 then
        event:setCostData(self, cards)
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(event:getCostData(self), "wdtx__axe", player, player)
    if room.logic.class.name == "wdtx_logic" then
      local eid = player:getEquipment(Card.SubtypeWeapon)
      if not eid then return end
      local card = Fk:getCardById(eid)
      if card:getMark("@up_easyhurt") > 0 then
        local tar = data.to
        room:addPlayerMark(tar, "@up_easyhurt", card:getMark("@up_easyhurt"))
        if not tar:hasSkill("easyHurtSkill") then
          room:handleAddLoseSkills(tar, "easyHurtSkill", nil, false)
        end
      end
    end
    return true
  end,
})

wdtx__axeSkill:addEffect(fk.Damaged, {
  name = "#wdtx__axe_skill",
  attached_equip = "wdtx__axe",
  priority = 11,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(wdtx__axeSkill.name) then return end
    return data.from == player and data.card.trueName == "slash" and not data.to.dead
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tar = target
    room:addPlayerMark(tar, "@up_easyhurt", 1)
    if not tar:hasSkill("easyHurtSkill") then
      room:handleAddLoseSkills(tar, "easyHurtSkill", nil, false)
    end
  end,
})


return wdtx__axeSkill
